* germany analysis 

use "gles_long.dta", clear

xtset lfdn wave
svyset lfdn [pw=wei_mz]

encode education, gen(edu)
encode gender, gen(sex)


**** Analysis of AfD VOTE  

svy:  reg voteAfD c.immigration##i.wave learning_status  c.europe##i.wave  c.ideology##i.wave  ///
            age  i.sex  i.edu  i.residence i.social_status if wave!=1
      

margins, dydx(immigration) at(  wave=(2 3)   )


svy:  reg voteAfD c.immigration##i.wave##ib3.learning_status  ///
            age  i.sex  i.edu  i.residence i.social_status if wave!=1
      
outreg2 using TABLE_Priming_GER_R2.doc, replace ctitle(Learning) label  nocon bd(2) sd(2)   r2


svy:  reg voteAfD c.immigration##i.wave##ib3.learning_status  c.europe##i.wave  c.ideology##i.wave  ///
            age  i.sex  i.edu  i.residence i.social_status if wave!=1
      
outreg2 using TABLE_Priming_GER_R2.doc, append ctitle(Learning) label  nocon bd(2) sd(2)   r2

margins, dydx(immigration) at(  wave=(2 3)  learning_status=(1(1)4) )





* Cross-lagged models
svy:  reg voteAfD c.L.voteAfD##i.wave  c.L.immigration##i.wave  if learning_status ==4

outreg2 using TABLE_Learning_Germany.doc, replace ctitle(Learning) label  nocon bd(2) sd(2)   


margins,  predict() at( wave=(2 3) L.immigration=(0 1))
marginsplot, leg(position(6)) yscale(range(0 .5)) ylabel(0(.1).5) aspect(1) scale(1.5)
graph save g1.gph, replace


svy: reg immigration c.L.immigration##i.wave   c.L.voteAfD##i.wave  if learning_status ==4


outreg2 using TABLE_Learning_Germany.doc, append ctitle(Opinion change) label  nocon bd(2) sd(2)   


margins,  predict() at( wave=(2 3) L.voteAfD=(0 1))
marginsplot, leg(position(6)) yscale(range(.5 1)) ylabel(.5(.1)1) aspect(1) scale(1.5)
graph save g2.gph, replace


graph combine g1.gph g2.gph





